﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DynaPrecision.FunctionAnalysis
{
	public class FunctionSum<TInput,TResult,TLeft,TRight>:IFunction<TInput,TResult>
		where TLeft:IFunction<TInput,TResult>
		where TRight:IFunction<TInput,TResult>
	{
		public TLeft LeftFunction { get; set; }
		public TRight RightFunction { get; set; }



		#region IFunction<TInput,TResult> Members

		public Func<TInput, TResult> Functor
		{
			get { return x=>LeftFunction.Functor(x)+(dynamic)RightFunction.Functor(x); }
		}

		public IFunction<TInput, TResult> Derivative
		{
			get
			{
				var result = new FunctionSum<TInput, TResult, IFunction<TInput, TResult>, IFunction<TInput, TResult>>();
				result.LeftFunction = LeftFunction.Derivative;
				result.RightFunction = RightFunction.Derivative;
				return result;
			}
		}

		public IFunction<TInput, TResult> Integral
		{
			get
			{
				var result = new FunctionSum<TInput, TResult, IFunction<TInput, TResult>, IFunction<TInput, TResult>>();
				result.LeftFunction = LeftFunction.Integral;
				result.RightFunction = RightFunction.Integral;
				return result;
			}
		}

		#endregion
	}
}
